import React, { Component } from 'react';
import {Tabs } from 'antd';
import {InvoiceTable} from './InvoiceTable';
import {AddForm4,AddForm2} from './FormInvoice';
const TabPane = Tabs.TabPane;
 class Invoice extends Component{
    constructor(props){
        super(props);
        this.state={
            invoiceType:'',
            invoiceId:''
        }
        this.tabEndCallback = this.tabEndCallback.bind(this)
        this.databack = this.databack.bind(this);
    }
    tabEndCallback(invoiceType){//tab标签的回调
        this.setState({
            invoiceType:invoiceType
        },function(){
            if(invoiceType=='1'){
                this.props.databack(invoiceType,'') ;               
            }
            else{
                this.props.databack(invoiceType,this.refs['InvoiceTable'+invoiceType].state.invoiceId)
            }
        })
    }
    databack(invoiceType,invoiceId){//发票列表的回调
        this.props.databack(invoiceType,invoiceId);
    }
    render(){
        const invoiceType = "2";
        return (
           <Tabs animated={false} onChange={this.tabEndCallback} defaultActiveKey={invoiceType} className="invoiceTab">
                <TabPane tab="不开发票" key="1"></TabPane>
                <TabPane tab="电子发票" key="4" forceRender={true}>
                    <InvoiceTable databack={this.databack} invoiceType="4" defaultInviceType={invoiceType} ref="InvoiceTable4" component={AddForm4}/>
                 </TabPane>
                <TabPane tab="增值税普通发票" key="2" forceRender={true}>
                     <InvoiceTable databack={this.databack} invoiceType="2" defaultInviceType={invoiceType} ref="InvoiceTable2"  component={AddForm2}/>
                 </TabPane>
                <TabPane tab="增值税专用发票" key="3" forceRender={true}> 
                    <InvoiceTable databack={this.databack} invoiceType="3" defaultInviceType={invoiceType} ref="InvoiceTable3"  component={AddForm4}/>
                </TabPane>
           </Tabs>
        )
    }
 }
 export {Invoice};